import random
import requests
from util.getproxy import get_proxy_poll, get_proxy

urls = [f'https://httpbin.org/get?age={i}'for i in range(1,10)]
proxies = get_proxy_poll()

while len(urls):
    url = urls.pop(0)
    proxy = random.choice(proxies)
    try:
        response = requests.get(url, proxies=proxy)
        print(response.json())
    except requests.exceptions.RequestException as e:
        print('代理失败，更换代理')
        proxies.remove(proxy)
        proxies.append(get_proxy())
        urls.append(url)
    except Exception as e:
        print('未知异常')
        urls.append(url)

